package ci092.trabalho.web;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import ci092.trabalho.Candidato;
import ci092.trabalho.DadosInscricao;

import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@RooWebScaffold(path = "candidatoes", formBackingObject = Candidato.class)
@RequestMapping("/candidatoes")
@Controller
public class CandidatoController {
	
	

    @RequestMapping(method = RequestMethod.POST)
    public String create(@Valid Candidato candidato, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
        if (bindingResult.hasErrors()) {
            uiModel.addAttribute("candidato", candidato);
            addDateTimeFormatPatterns(uiModel);
            return "candidatoes/create";
        }
        uiModel.asMap().clear();
        candidato.persist();
        DadosInscricao dadosInscricao = new  DadosInscricao();
        dadosInscricao.setCandidato(candidato);
        dadosInscricao.persist();
        
        uiModel.addAttribute("dadosInscricao", dadosInscricao);
    	return "dadosinscricaos/update";
      
    }
    
}